package extras;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.http.ParseException;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.widget.Toast;

/**
 * Clase para usar metodos utiles que se usan en todos lados
 * @author Marco
 *
 */

public class Utilities {
	
	Context contexto;
	
	public Utilities(Context pContexto){
		contexto = pContexto;
	}
	
	public static void makeToastLong(Context pContexto,String msg){
		Toast.makeText(pContexto, msg, Toast.LENGTH_LONG).show(); 
		
	}
	
	public static Date getDateFromString(String fecha){
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
		try{
			return sdf.parse(fecha);
		}
	catch (java.text.ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
	
	public static String getEmail(Context contexto){
		  AccountManager manager = (AccountManager) contexto.getSystemService(Context.ACCOUNT_SERVICE);
	        Account[] list = manager.getAccounts();
	        for(Account cuenta:list){
	        	return cuenta.name;
	        }
	        
	        return "-";
	}

	public static String obtenerHoraActual()
	{
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
		return sdf.format(new java.util.Date());
	}
	
	public static String obtenerFechaActual(){
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
		return sdf.format(new java.util.Date());
	}
	
	public static String sumarMinutosAFecha(int minutos){
		Date fechaActual = new Date();
		Calendar cal = new GregorianCalendar();
		cal.setTimeInMillis(fechaActual.getTime());
		cal.add(Calendar.MINUTE, minutos);
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
		return sdf.format(new Date(cal.getTimeInMillis()));
	}
}
